#include "BBox.h"
#include <algorithm>

BBox::BBox(const Vector3f& min, const Vector3f& max)
  : min(min), max(max) { extent = max - min; }

BBox::BBox(const Vector3f& p)
  : min(p), max(p) { extent = max - min; }

  void BBox::expandToInclude(const Vector3f& p) {
    min = ::min(min, p);
    max = ::max(max, p);
    extent = max - min;
  }

void BBox::expandToInclude(const BBox& b) {
  min = ::min(min, b.min);
  max = ::max(max, b.max);
  extent = max - min;
}

uint32_t BBox::maxDimension() const {
  uint32_t result = 0;
  if(extent.y > extent.x) result = 1;
  if(extent.z > extent.y) result = 2;
  return result;
}

float BBox::surfaceArea() const {
  return 2.f*( extent.x*extent.z + extent.x*extent.y + extent.y*extent.z );
}

